<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\AgentMoney
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property int $agent_id 代理商ID
 * @property string $pre_money 变更前余额
 * @property string $money 变更金额
 * @property string $after_money 变更后余额
 * @property string|null $remark 变更备注
 * @property int $type 变更类型:0=后台修改,1=订单金额,2=提现金额
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney query()
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereAfterMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereAgentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney wherePreMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereUserId($value)
 * @mixin \Eloquent
 * @property int $city_id 市ID
 * @property int $district_id 区ID
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereCityId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AgentMoney whereDistrictId($value)
 */
class AgentMoney extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'agent_moneys';


    protected $fillable = [
        'type',
        'user_id',
        'agent_id',
        'pre_money',
        'money',
        'after_money',
        'remark',
    ];

    /**
     * 获取用户的
     * @param $user_id
     * @return array
     */
    public static function getList($user_id){
        $state = request()->input('state',0);
        $limit = request()->input('limit',10);
        $list = self::whereUserId($user_id)
            ->when($state,function ($query,$value){
                $query->where("money",$value==1?">":"<",0);
            })
            ->paginate($limit);
        $data['items'] = $list->items();
        $data['lastPage'] = $list->lastPage();
        $data['total'] = $list->total();
        return $data;
    }


}
